Date.prototype.Format = function(fmt) { //author: meizz 
	var o = {
		"M+" : this.getMonth() + 1, //月份 
		"d+" : this.getDate(), //日 
		"h+" : this.getHours(), //小时 
		"m+" : this.getMinutes(), //分 
		"s+" : this.getSeconds(), //秒 
		"q+" : Math.floor((this.getMonth() + 3) / 3), //季度 
		"S" : this.getMilliseconds()
	//毫秒 
	};
	if (/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	for ( var k in o)
		if (new RegExp("(" + k + ")").test(fmt))
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
					: (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}

jQuery.ajaxSetup({
    complete:function(XMLHttpRequest,textStatus){ 
      var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); //通过XMLHttpRequest取得响应头，sessionstatus，  
	         if(sessionstatus=="timeout"){ 
	        	 //如果超时就处理 ，指定要跳转的页面  
	        	 //window.location.replace("login");
	        	 window.top.location.href="login";
	         }   
     }   
});

//公用方法
var Fitz = {
	    listPage: function(url, itemsPerPage, currentPage){
			jQuery.ajax({
				url: url,
				type: 'get',
				data: {"itemsPerPage":itemsPerPage, "currentPage":currentPage},
				success: function(json) {
					jQuery("#main").html(json);
				},
				error: function(xhr, textStatus, errorThrown){
					alert(errorThrown);
				}
			});
		}, 
		loadForm: function(url){
			jQuery.ajax({
				url: url,
				type: 'get',
				success: function(json) {
					jQuery("#main").html(json);
				},
				error: function(xhr, textStatus, errorThrown){
					alert(errorThrown);
				}
			});
		},
		alert: function(content, cbk){
			jQuery.alert({
				icon: 'icon-ok-sign',
				confirmButtonClass: 'btn yellow',
				confirmButton: '确定',
			    title: "Alert!",
			    content: content,
			    confirm: function(){
			        if(cbk) cbk();
			    }
			});
		},
		confirm: function(content,cbk){
			jQuery.confirm({
				icon: 'icon-warning-sign',
			    title: 'Confirm!',
			    confirmButton: '确定',
			    confirmButtonClass: 'btn red',
			    cancelButton: '关闭',
			    content: content,
			    confirm: function(){
			    	if(cbk) cbk();
			    }
			});
		},
		validate: function(params){
			params.form.validate({
				rules:params.rules,
				messages: params.messages
			});
			
			if (params.form.valid() && params.cbk) {
				params.cbk();
			}
		}
		
	};

